package cn.crm.service.impl;

import cn.crm.dao.CstCustomerDao;
import cn.crm.pojo.CstCustomer;
import cn.crm.service.CstCustomerService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.List;

@Transactional(rollbackFor = Exception.class)//事务回滚
@Service
public class CstCustomerServiceImpl extends ServiceImpl<CstCustomerDao, CstCustomer> implements CstCustomerService {
    @Autowired
    private CstCustomerDao cstCustomerDao;
    @Override
    public List<CstCustomer> getCount() {
        return cstCustomerDao.getCount();
    }

    @Override
    public List<CstCustomer> getConditionSearchPage(HashMap condition) {
        LambdaQueryWrapper<CstCustomer> lqw = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(condition.get("custNo")))
            lqw.like(CstCustomer::getCustNo,condition.get("custNo"));
        if (!ObjectUtils.isEmpty(condition.get("custName")))
            lqw.like(CstCustomer::getCustName,condition.get("custName"));
        if (!ObjectUtils.isEmpty(condition.get("custRegion"))&&!"全部".equals(condition.get("custRegion")))
            lqw.like(CstCustomer::getCustRegion,condition.get("custRegion"));
        if (!ObjectUtils.isEmpty(condition.get("custManagerName")))
            lqw.like(CstCustomer::getCustManagerName,condition.get("custManagerName"));
        if (!ObjectUtils.isEmpty(condition.get("custLevelLabel"))&&!"全部".equals(condition.get("custLevelLabel")))
            lqw.like(CstCustomer::getCustLevelLabel,condition.get("custLevelLabel"));
        lqw.orderByAsc(CstCustomer::getCustId);
        return cstCustomerDao.selectList(lqw);
    }
}
